package com.kylin.common.weixin.miniapp;

import com.alibaba.fastjson2.JSONObject;
import com.kylin.common.weixin.util.WxRequest;

/**
 * 授权登录相关接口
 *
 * @author wuhao
 * @version 1.0 - 2019-11-20
 */
public class AuthorizeService {

    /**
     * 登录凭证校验地址
     */
    public static final String CODE_TO_SESSION_URL = "/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";


    /**
     * 通过code获取用户openid以及会话密钥
     * @param appId 小程序唯一标识
     * @param appSecret  小程序appsecret
     * @param code 登录时获取的 code
     * @return eg.
     * @version 1.0  by wuhao at 2019-11-20
     */
    public static JSONObject codeToSession(String appId,String appSecret, String code){
        String url = String.format(CODE_TO_SESSION_URL,appId,appSecret,code);
        return WxRequest.get(url);
    }
}
